package com.ruoyi.device.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.device.api.domain.DeviceOnOffLog;
import com.ruoyi.device.service.IDeviceOnOffLogService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 设备上下线日志Controller
 * 
 * @author luogongquan
 * @date 2024-09-06
 */
@RestController
@RequestMapping("/deviceOnOffLog")
public class DeviceOnOffLogController extends BaseController
{
    @Autowired
    private IDeviceOnOffLogService deviceOnOffLogService;

    /**
     * 查询设备上下线日志列表
     */
    @RequiresPermissions("device:deviceOnOffLog:list")
    @GetMapping("/list")
    public TableDataInfo list(DeviceOnOffLog deviceOnOffLog)
    {
        startPage();
        List<DeviceOnOffLog> list = deviceOnOffLogService.selectDeviceOnOffLogList(deviceOnOffLog);
        return getDataTable(list);
    }

    /**
     * 导出设备上下线日志列表
     */
    @RequiresPermissions("device:deviceOnOffLog:export")
    @Log(title = "设备上下线日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceOnOffLog deviceOnOffLog)
    {
        List<DeviceOnOffLog> list = deviceOnOffLogService.selectDeviceOnOffLogList(deviceOnOffLog);
        ExcelUtil<DeviceOnOffLog> util = new ExcelUtil<DeviceOnOffLog>(DeviceOnOffLog.class);
        util.exportExcel(response, list, "设备上下线日志数据");
    }

    /**
     * 获取设备上下线日志详细信息
     */
    @RequiresPermissions("device:deviceOnOffLog:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deviceOnOffLogService.selectDeviceOnOffLogById(id));
    }

    /**
     * 新增设备上下线日志
     */
    @RequiresPermissions("device:deviceOnOffLog:add")
    @Log(title = "设备上下线日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceOnOffLog deviceOnOffLog)
    {
        return toAjax(deviceOnOffLogService.insertDeviceOnOffLog(deviceOnOffLog));
    }

    /**
     * 修改设备上下线日志
     */
    @RequiresPermissions("device:deviceOnOffLog:edit")
    @Log(title = "设备上下线日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceOnOffLog deviceOnOffLog)
    {
        return toAjax(deviceOnOffLogService.updateDeviceOnOffLog(deviceOnOffLog));
    }

    /**
     * 删除设备上下线日志
     */
    @RequiresPermissions("device:deviceOnOffLog:remove")
    @Log(title = "设备上下线日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deviceOnOffLogService.deleteDeviceOnOffLogByIds(ids));
    }
}
